package network.udp;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

public class DictServer extends EchoServer {
    private Map<String,String> dict = new HashMap<>();

    public DictServer(int port) throws SocketException {
        super(port);

        dict.put("cat", "小猫");
        dict.put("dog", "小狗");
        dict.put("bird", "小鸟");
        dict.put("fish", "鱼");
        dict.put("pig", "猪");
        dict.put("man", "男人");
        dict.put("woman", "女人");
        dict.put("good", "好的");
        dict.put("bad", "不好");
        dict.put("chicken", "小鸡");

    }
    @Override
    public String process(String request) {
        //方法重写，本质上就是对父类功能的扩展
        //本来父类是“没有翻译功能的”，通过重写把功能加上
        return dict.getOrDefault(request,"该单词没有查到");
    }

    public static void main(String[] args) throws IOException {
        DictServer dictServer = new DictServer(9090);
        dictServer.start();
    }
}
